package cn.xfdzx.android.apps.shop.fragment;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.luck.picture.lib.tools.ToastUtils;

import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.myshop.CreateZhiBoActivity;
import cn.xfdzx.android.apps.shop.activity.myshop.GoodManagementActivity;
import cn.xfdzx.android.apps.shop.activity.myshop.bluedevic.PrintSetActivity;
import cn.xfdzx.android.apps.shop.activity.myshop.ShopAddGoodsActivity;
import cn.xfdzx.android.apps.shop.activity.ruzhu.OrderManagementActivity;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpFragment;
import cn.xfdzx.android.apps.shop.bean.BaseObjectBean;
import cn.xfdzx.android.apps.shop.bean.ShopInDetailsBeen;
import cn.xfdzx.android.apps.shop.bean.ShopTimeBean;
import cn.xfdzx.android.apps.shop.contract.ShopManagerContract;
import cn.xfdzx.android.apps.shop.presenter.ShopManagerPresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.ProgressDialog;
import cn.xfdzx.android.apps.shop.util.StreamUtil;
import cn.xfdzx.android.apps.shop.util.Utils;
import cn.xfdzx.android.apps.shop.widget.SelShopTimePopwindow;
import cn.xfdzx.android.apps.shop.widget.WheelPickerTime;

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;

/**
 * 店铺中心店铺fragment
 * **/
public class ShopManagerFragment extends BaseMvpFragment<ShopManagerPresenter> implements ShopManagerContract.View ,View.OnClickListener{


    TextView tvAddGood;
    ImageView ivShopTitle;
    TextView tvShopNameTitle;
    TextView tvIntroduce;
    TextView tvInformation;
    TextView tvZhuying;
    TextView tvRetailName;
    TextView tvShopName;
    TextView tvShopId;
    TextView tvLianxi;
    TextView tvPhone;
    TextView tvShopAddress;
    RelativeLayout rlGoods;
    TextView tvGoodLibrary;
    TextView tvChuShou;
    TextView tvXiaJia;
    RelativeLayout rlTitle;
    RelativeLayout rlZhibo;
    RelativeLayout rlOrder;
    private RelativeLayout rl_setbluedevic;//打印机设置
    private RelativeLayout rl_settime;//设置营业时间
    private String type = "";//
    private int isClose;
    private int currentShopState;//当前店铺经营状态
    private ImageView img_worktime;
    private ImageView img_freetime;
    TextView tv_shopstate;
    private SelShopTimePopwindow selShopTimePopwindow;//选择店铺经营时间弹窗
    private WheelPickerTime wheelPickerleft,wheelPickerright;//左右时间
    private String startTime="00:00";
    private String endTime="00:00";
    private String shopTime="";
    private String oldShopTime="";
    private List<ShopTimeBean> shopTimeBeanList = new ArrayList<>();
    private ImageView img_settime;//设置根据经营时间自动变更状态
    private boolean isSet;//是否设置了经营时间
    private Dialog dialog;//去设置时间弹窗
    private String updateShopInfoType = "";//1,修改店铺营业或者休息操作，2，修改店铺营业时间操作3.设置自动开关操作
    private boolean isAuto = false;//1,修改店铺营业或者休息操作，2，修改店铺营业时间操作3.设置自动开关操作4
    private boolean isNosetAndGoset = false;//如果没有设置过时间，并点击了设置确定按钮
    private ShopInDetailsBeen detailsBeen;
    private TextView tv_setworktime;//营业时间显示

    TextView tvDaiZhi, tvDaiFa, tvDaiShou, tvShouHou;
    LinearLayout llOrderState_1, llOrderState_2, llOrderState_3, llOrderState_4;

    @Override
    protected void initView(View view) {

        tvDaiZhi = view.findViewById(R.id.tv_dai_zhi);
        tvDaiFa = view.findViewById(R.id.tv_dai_fa);
        tvDaiShou = view.findViewById(R.id.tv_dai_shou);
        tvShouHou = view.findViewById(R.id.tv_shou_hou);
        llOrderState_1 = view.findViewById(R.id.ll_order_state_1);
        llOrderState_2 = view.findViewById(R.id.ll_order_state_2);
        llOrderState_3 = view.findViewById(R.id.ll_order_state_3);
        llOrderState_4 = view.findViewById(R.id.ll_order_state_4);
        tvAddGood = view.findViewById(R.id.tv_add_good);
        ivShopTitle = view.findViewById(R.id.iv_shop_title);
        tvShopNameTitle = view.findViewById(R.id.tv_shop_name_title);
        tvIntroduce = view.findViewById(R.id.tv_introduce);
        tvInformation = view.findViewById(R.id.tv_information);
        tvZhuying = view.findViewById(R.id.tv_zhuying);
        tvRetailName = view.findViewById(R.id.tv_retail_name);
        tvShopName = view.findViewById(R.id.tv_shop_name);
        tvShopId = view.findViewById(R.id.tv_shop_id);
        tvLianxi = view.findViewById(R.id.tv_lianxi);
        tvPhone = view.findViewById(R.id.tv_phone);
        tvShopAddress = view.findViewById(R.id.tv_shop_address);
        rlGoods = view.findViewById(R.id.rl_goods);
        tvChuShou = view.findViewById(R.id.tv_chu_shou);
        tvXiaJia = view.findViewById(R.id.tv_xia_jia);
        tvGoodLibrary = view.findViewById(R.id.tv_good_library);

        rlTitle = view.findViewById(R.id.rl_title);
        rlZhibo = view.findViewById(R.id.rl_zhibo);
        rlOrder = view.findViewById(R.id.rl_order);
        tv_shopstate = view.findViewById(R.id.tv_shopstate);
        rl_settime = view.findViewById(R.id.rl_settime);
        rl_setbluedevic = view.findViewById(R.id.rl_setbluedevic);
        tvAddGood.setOnClickListener(this);
        rlGoods.setOnClickListener(this);
        rlOrder.setOnClickListener(this);
        rlTitle.setOnClickListener(this);
        rl_settime.setOnClickListener(this);
        llOrderState_1.setOnClickListener(this);
        llOrderState_2.setOnClickListener(this);
        llOrderState_3.setOnClickListener(this);
        llOrderState_4.setOnClickListener(this);
        tvChuShou.setOnClickListener(this);
        tvXiaJia.setOnClickListener(this);
        tvGoodLibrary.setOnClickListener(this);
        rl_setbluedevic.setOnClickListener(this);
        mPresenter = new ShopManagerPresenter();
        mPresenter.attachView(this);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_shop_manager;
    }

    @Override
    public void showLoading() {
        if (!ProgressDialog.getInstance().materialDialog.isShowing()) {
            ProgressDialog.getInstance().show(getActivity());
        }
    }

    @Override
    public void hideLoading() {
        ProgressDialog.getInstance().dismiss();
    }


    public void setData(ShopInDetailsBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            detailsBeen=bean;
            RoundedCorners roundedCorners = new RoundedCorners(20);
            //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
            RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(200, 200);
            options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                    .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
                    .error(R.drawable.icon_defult);
//            RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);

            isClose = bean.getData().getIs_close();
            currentShopState = bean.getData().getIs_close();
            if (isClose == 0){
                tv_shopstate.setBackground(getResources().getDrawable(R.drawable.circle_greenslide));
            }else if (isClose == 1){
                tv_shopstate.setBackground(getResources().getDrawable(R.drawable.circle_redslide));
            }
            Glide.with(getActivity()).load(bean.getData().getLogo()).apply(options.transform(new CircleCrop(), roundedCorners)).into(ivShopTitle);

            if (EmptyUtil.isNotEmpty(bean.getData().getBusiness_hours())){//是否设置过经营时间
                isSet = true;
            }else {
                isSet = false;
            }
            if (bean.getData().getSales_model() == 0) {
                type = "0";
                tvRetailName.setVisibility(View.VISIBLE);
                tvZhuying.setVisibility(View.GONE);
                tvInformation.setText("经营信息：" + "零售");
                tvShopNameTitle.setText(bean.getData().getOffline_shop_name());
                tvRetailName.setText("店铺名称：" + bean.getData().getOffline_shop_name());
                rlTitle.setBackgroundColor(getResources().getColor(R.color.color_FB9129));
                tvAddGood.setBackgroundResource(R.drawable.dfb9129_bg_r3);
            } else {
                type = "1";
                tvShopNameTitle.setText(bean.getData().getName());
                tvAddGood.setBackgroundResource(R.drawable.d02c557_bg_r3);
                tvRetailName.setVisibility(View.GONE);
                tvInformation.setText("经营信息：" + "批发");
                tvZhuying.setVisibility(View.VISIBLE);
                tvZhuying.setText("主营：" + bean.getData().getSalecate());
                rlTitle.setBackgroundColor(getResources().getColor(R.color.color_02C557));
            }

            tvDaiZhi.setText(bean.getData().getOrderStatusNum().getTo_be_paid_count() + "");

            tvDaiFa.setText(bean.getData().getOrderStatusNum().getTo_be_delivered_count() + "");

            tvDaiShou.setText(bean.getData().getOrderStatusNum().getGoods_to_be_received_count() + "");

            tvShouHou.setText(bean.getData().getOrderStatusNum().getRefund_order_count() + "");

            tvIntroduce.setText("公司介绍：" + bean.getData().getIntro());

            tvShopId.setText("门店编码："+bean.getData().getId());
            tvShopName.setText("门店名称：" + bean.getData().getName());
            tvLianxi.setText("联系人：" + bean.getData().getBank_open_name());
            tvPhone.setText("联系电话：" + bean.getData().getMobile());
            tvShopAddress.setText("门店地址：" + bean.getData().getWhole_address() + bean.getData().getStore_current_address());
            rlZhibo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Utils.isFastClick()) {
                        if (bean.getData().isAnchor()) {
                            mPresenter.anchorApply();
                        } else {
                            startNextActivity();
                        }
                    }
                }
            });
        } else {
            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    private void startNextActivity() {
        intent = new Intent(getActivity(), CreateZhiBoActivity.class);
        intent.putExtra("type", type);
        if (detailsBeen.getData().getSales_model() == 0) {
            intent.putExtra("name", detailsBeen.getData().getOffline_shop_name());
        } else {
            intent.putExtra("name", detailsBeen.getData().getName());
        }
        intent.putExtra("image", detailsBeen.getData().getLogo());
        startActivity(intent);
    }

    @Override
    public void onError(Throwable throwable) {
        Toast.makeText(getActivity(), "网络请求出错", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onAnchorApplySuccess(BaseObjectBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            startNextActivity();
        } else {
            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onupdateBusinessInfoSuccess(ShopInDetailsBeen bean,String type) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            ToastUtils.s(getActivity(),"修改成功");
            if (type.equals("1")){//修改店铺经营状态操作
//                if (isClose == 1){//点击了闭店
//                    currentShopState = 1;
//                }else {
//                    currentShopState = 0;
//                }

            }
            if (type.equals("2")){//代表是修改根据店铺经营时间自动开关店请求成功
                isSet = true;
                tv_setworktime.setText("营业时间:"+shopTime);
                if (isNosetAndGoset){//第一次设置经营时间成功
                    isAuto = true;
                    img_settime.setImageResource(R.drawable.icon_open);
                }
            }

            if (type.equals("3")){//如果是设置自动开关操作
                if (isAuto = true){
                    isAuto = false;
                    img_settime.setImageResource(R.drawable.icon_close);
                }else {
                    isAuto = true;
                    img_settime.setImageResource(R.drawable.icon_open);
                }
            }
            isClose = bean.getData().getIs_close();
            currentShopState = bean.getData().getIs_close();

            if (isClose == 0){
                img_worktime.setVisibility(View.VISIBLE);
                img_freetime.setVisibility(View.INVISIBLE);
                tv_shopstate.setBackground(getResources().getDrawable(R.drawable.circle_greenslide));
                popupWindow.dismiss();
            }else if (isClose == 1){
                img_worktime.setVisibility(View.INVISIBLE);
                img_freetime.setVisibility(View.VISIBLE);
                tv_shopstate.setBackground(getResources().getDrawable(R.drawable.circle_redslide));
                popupWindow.dismiss();
            }
        } else {
            if (type.equals("2")){//设置时间失败
                isNosetAndGoset = false;
            }
            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    Intent intent;


    public static ShopManagerFragment newInstance(int userUid) {
        Bundle bundle = new Bundle();
        ShopManagerFragment fragment = new ShopManagerFragment();
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_add_good:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), ShopAddGoodsActivity.class);
                    intent.putExtra("type", type);
                    startActivity(intent);
                }
                break;
            case R.id.rl_goods:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), GoodManagementActivity.class);
                    intent.putExtra("type", type);
                    intent.putExtra("position", 1);
                    intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
                    intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent);
                }
                break;
            case R.id.tv_good_library:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), GoodManagementActivity.class);
                    intent.putExtra("type", type);
                    intent.putExtra("position", 0);
                    intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
                    intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent);
                }
                break;
            case R.id.tv_chu_shou:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), GoodManagementActivity.class);
                    intent.putExtra("type", type);
                    intent.putExtra("position", 2);
                    intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
                    intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent);
                }
                break;
            case R.id.tv_xia_jia:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), GoodManagementActivity.class);
                    intent.putExtra("type", type);
                    intent.putExtra("position", 3);
                    intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
                    intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent);
                }
                break;
            case R.id.rl_order:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), OrderManagementActivity.class);
                    intent.putExtra("type", type);
                    intent.putExtra("position", 0);
                    startActivity(intent);
                }
                break;
            case R.id.ll_order_state_1:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), OrderManagementActivity.class);
                    intent.putExtra("position", 1);
                    intent.putExtra("type", type);
                    startActivity(intent);
                }
                break;
            case R.id.ll_order_state_2:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), OrderManagementActivity.class);
                    intent.putExtra("position", 2);
                    intent.putExtra("type", type);
                    startActivity(intent);
                }
                break;
            case R.id.ll_order_state_3:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), OrderManagementActivity.class);
                    intent.putExtra("position", 3);
                    intent.putExtra("type", type);
                    startActivity(intent);
                }
                break;
            case R.id.ll_order_state_4:
                if (Utils.isFastClick()) {
                    intent = new Intent(getActivity(), OrderManagementActivity.class);
                    intent.putExtra("position", 5);
                    intent.putExtra("type", type);
                    startActivity(intent);
                }
                break;
            case R.id.rl_title://店铺名称头像点击
                if (Utils.isFastClick()) {
                    if (EmptyUtil.isNotEmpty(popupWindow)) {
                        if (popupWindow.isShowing()) {
                            popupWindow.dismiss();
                        }
                    }
                    if (  popupWindow==null) {
                        showPop(rlTitle, currentShopState);
                    }else {
                        popupWindow.showAsDropDown(rlTitle, 0, 0);
                    }
                    // showSelTimePop();
                }
                break;
            case R.id.rl_settime://设置营业时间
                if (  popupWindow==null) {
                    showPop(rlTitle, currentShopState);
                }else {
                    popupWindow.showAsDropDown(rlTitle, 0, 0);
                }
                break;
            case R.id.rl_setbluedevic://设置蓝牙打印机
                intent = new Intent(getActivity(), PrintSetActivity.class);
                startActivity(intent);
                break;



        }
    }

    /**
     * 去设置弹窗
     * */
    public void showGoSetTimeDialog(){
        dialog = Utils.addDialog(getActivity(), R.layout.dialog, R.string.nosettime, R.string.gosettime, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // showSelTimePop();
                dialog.dismiss();
            }
        },R.color.color_FB9129);
        dialog.show();
    }

    /**
     * 更新店铺状态弹窗
     * */
    private PopupWindow popupWindow;
    private void showPop(View itemView,int state) {
        View view = LayoutInflater.from(getActivity()).inflate(
                R.layout.popwindow_updateshopstate, null);
        popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());// 点击返回按钮popwindow消失

        //popupWindow.showAtLocation(itemView, Gravity.BOTTOM, 0, 0);

        View view_other = view.findViewById(R.id.view_other);
        tv_setworktime = view.findViewById(R.id.tv_setworktime);
        img_worktime = (ImageView) view.findViewById(R.id.img_worktime);
        img_freetime = (ImageView) view.findViewById(R.id.img_freetime);
        img_settime = (ImageView) view.findViewById(R.id.img_settime);
        TextView tv_circlegreen = (TextView) view.findViewById(R.id.tv_circlegreen);
        TextView tv_circlered = (TextView) view.findViewById(R.id.tv_circlered);
        RelativeLayout rl_worktime = (RelativeLayout) view.findViewById(R.id.rl_worktime);
        RelativeLayout rl_freetime = (RelativeLayout) view.findViewById(R.id.rl_freetime);
        if (EmptyUtil.isNotEmpty(detailsBeen)){
            if (EmptyUtil.isNotEmpty(detailsBeen.getData().getBusiness_hours())){
                oldShopTime = detailsBeen.getData().getBusiness_hours();
                if (EmptyUtil.isNotEmpty(shopTime)){
                    tv_setworktime.setText("营业时间:"+shopTime);
                }else {
                    tv_setworktime.setText("营业时间:"+oldShopTime);
                }
                if (oldShopTime.contains("-")) {
                    startTime =oldShopTime.substring(0,oldShopTime.indexOf("-"));
                    endTime =oldShopTime.substring( oldShopTime.indexOf("-")+1,oldShopTime.length());
                }
            }else {
                tv_setworktime.setText("设置营业时间");
            }
        }

        if (state == 0){
            img_worktime.setVisibility(View.VISIBLE);
            img_freetime.setVisibility(View.INVISIBLE);
        }else {
            img_worktime.setVisibility(View.INVISIBLE);
            img_freetime.setVisibility(View.VISIBLE);
        }
        view_other.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        img_settime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isSet){//如果设置过了经营时间
                    //设置根据时间自动开关店
                    Map<String,Object> map = new HashMap<>();
                    map.put("auto_modify_business_status",1);
                    updateShopInfoType = "3";
                    mPresenter.updateBusinessInfo(map,updateShopInfoType);
                }else {//没设置过经营时间，先去设置
                    showGoSetTimeDialog();
                }
            }
        });

        /**设置营业*/
        rl_worktime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Utils.isFastClick()) {
                    isClose = 0;
                    updateShopInfoType = "1";
//                    Map<String, Object> map = new HashMap<>();
//                    map.put("is_close", 0);
//                    mPresenter.updateBusinessInfo(map, updateShopInfoType);
                    showSelTimePop();
                }
            }
        });

        rl_freetime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Utils.isFastClick()) {
                    isClose = 1;
                    Map<String, Object> map = new HashMap<>();
                    map.put("is_close", 1);
                    updateShopInfoType = "1";
                    mPresenter.updateBusinessInfo(map, updateShopInfoType);
                }
            }
        });

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });
    }

    /**
     * 选择时间弹窗
     * **/
    public void showSelTimePop() {
        InputStream is = null;
        is = getResources().openRawResource(R.raw.shoptime);

        Type type = new TypeToken<List<ShopTimeBean>>() {
        }.getType();
        shopTimeBeanList = new Gson().fromJson(StreamUtil.stream2string(is, "UTF-8"), type);

        Log.e("shopTimeBeanList",shopTimeBeanList.size()+"----");
        selShopTimePopwindow = new SelShopTimePopwindow(getActivity(), R.layout.pw_seltime);
        selShopTimePopwindow.showPopupWindow();
        popupWindow.setOutsideTouchable(false);
        popupWindow.setFocusable(false);
        popupWindow.setTouchable(true);
        wheelPickerleft = selShopTimePopwindow.getRootView().findViewById(R.id.up_unit_left);
        wheelPickerright = selShopTimePopwindow.getRootView().findViewById(R.id.up_unit_right);
        wheelPickerleft.setDataList(shopTimeBeanList);
        wheelPickerright.setDataList(shopTimeBeanList);

        int oldLeft = 0;
        int oldRight = 0;

        for (int i = 0; i < shopTimeBeanList.size(); i++) {
            Log.e("shopTimeBeanList",startTime+"--"+shopTimeBeanList.get(i).getTime());
            if (startTime.equals(shopTimeBeanList.get(i).getTime())){
                oldLeft = i;

            }
            if (endTime.equals(shopTimeBeanList.get(i).getTime())){
                oldRight = i;
            }
        }
        wheelPickerleft.setCurrentPosition(oldLeft);
        wheelPickerright.setCurrentPosition(oldRight);
        selShopTimePopwindow.getRootView().findViewById(R.id.tv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selShopTimePopwindow.shareClose();
            }
        });
        selShopTimePopwindow.getRootView().findViewById(R.id.tv_queren).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startTime = shopTimeBeanList.get(wheelPickerleft.getCurrentPosition()).getTime();
                endTime = shopTimeBeanList.get(wheelPickerright.getCurrentPosition()).getTime();

//                if (EmptyUtil.isEmpty(startTime)||EmptyUtil.isEmpty(endTime)) {
////                    ToastUtils.s(getActivity(),"请选择开始和结束时间");
////                    return;
//                }else {
//                    startTime = "00:00";
//                    endTime = "00:00";
//                }
                shopTime = shopTimeBeanList.get(wheelPickerleft.getCurrentPosition()).getTime()+"-"+shopTimeBeanList.get(wheelPickerright.getCurrentPosition()).getTime();
//                Map<String,Object> map = new HashMap<>();
//                map.put("business_hours",shopTime);
//                updateShopInfoType = "2";
//                mPresenter.updateBusinessInfo(map,updateShopInfoType);
                updateShopInfoType = "2";
                Map<String,Object> map = new HashMap<>();
                map.put("business_hours",shopTime);
                if (EmptyUtil.isNotEmpty(oldShopTime)){//如果设置过时间需要传新的时间和老的时间，
                    map.put("old_business_hours",oldShopTime);
                }else {
                    map.put("old_business_hours",shopTime);
                }

                map.put("is_close", 0);
                mPresenter.updateBusinessInfo(map, updateShopInfoType);

                isNosetAndGoset = true;//去设置时间并且确定
                selShopTimePopwindow.shareClose();
            }
        });
    }

    @Override
    public void onDestroy() {
        if (selShopTimePopwindow!=null){
            if (selShopTimePopwindow.isShowing()){
                selShopTimePopwindow.dismiss();
            }
        }
        super.onDestroy();

    }
}
